@extends('Admin.layout.layout')
@section('content')
<div class="row">
	<div class="col-lg-12">
	    <h1 class="page-header">评价列表</h1>
	</div>
	<!-- /.col-lg-12 -->
</div>
<div class="row">
<!-- ==========提示框=========== -->
<div id="messagesuccess" class="alert alert-info" style="display:none">
    <span></span> 
</div>
<div id="messagedanger" class="alert alert-danger" style="display:none">
    <span></span>
</div>
<div class="col-lg-12">
    <div class="panel panel-default">
        <div class="panel-heading">
            DataTables Advanced Tables
        </div>
        <!-- /.panel-heading -->
        <div class="panel-body">
        	<form action="{{url('/admin/comment/index')}}" method="get" >
                <div class="dataTable_wrapper">
                <div id="dataTables-example_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
                <div class="row"><div class="col-sm-6">
                <div class="dataTables_length" id="dataTables-example_length">
                <label>显示<select name="num" aria-controls="dataTables-example" class="form-control input-sm">
                <option value="10" @if(!empty($request['num']) && $request['num'] == 10) { selected } @endif>10</option>
                <option value="25" @if(!empty($request['num']) && $request['num'] == 25) { selected } @endif>25</option>
                <option value="50" @if(!empty($request['num']) && $request['num'] == 50) { selected } @endif>50</option>
                <option value="100" @if(!empty($request['num']) && $request['num'] == 100) { selected } @endif>100</option>
                </select>条</label></div></div>
                <div class="col-sm-6">
                <div id="dataTables-example_filter" class="dataTables_filter">
                <label>评价id:<input type="text" name="id" class="form-control input-sm" placeholder="" aria-controls="dataTables-example" value="@if(!empty($request['id'])){{ $request['id'] }}@endif"><button class="btn btn-success">搜索</button></label></div></div></div>
        		</form>	        
                <div class="row">
                <div class="col-sm-12">
                <table class="table table-striped table-bordered table-hover dataTable no-footer" id="dataTables-example" role="grid" aria-describedby="dataTables-example_info">
                    <thead>
                        <tr role="row">
                        <th class="sorting_asc" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-sort="ascending" aria-label="Rendering engine: activate to sort column descending" style="width: 172px;">编号</th>
                        <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="Browser: activate to sort column ascending" style="width: 204px;">评价内容</th>
                        <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="Platform(s): activate to sort column ascending" style="width: 185px;">评价时间</th>
                        <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="Engine version: activate to sort column ascending" style="width: 149px;">评价商品</th>
                        <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="CSS grade: activate to sort column ascending" style="width: 110px;">评价用户</th>
                        <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="CSS grade: activate to sort column ascending" style="width: 110px;">操作</th></tr>
                    </thead>
                    <tbody>
                		@foreach($comment as $k=>$v)
		                <tr class="gradeA odd" role="row">
		                        <td class="sid">{{$v->id}}</td>
		                        <td>{{$v->content}}</td>
		                        <td>{{$v->time}}</td>
		                        <td class="center">{{$v->dingdan_id}}</td>
		                        <td class="center">{{$v->uid}}</td>
		                        <td class="center"> <button class=" delete fa fa-trash-o btn btn-danger btn-sm">删除</button></td>
		                    </tr>
		                @endforeach 
                    </tbody>
                </table>
                <div class="col-sm-12 col-sm-offset-8">
                {!!$comment->appends($request)->render()!!}
                </div>
                </div>
                </div>
            </div>
        </div>
        <!-- /.panel-body -->
    </div>
    <!-- /.panel -->
</div>
<!-- /.col-lg-12 -->
</div>
@endsection

@section('myjs')
<script type="text/javascript">
$.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
});
	$('.delete').click(function(){
		var id = $(this).parents('tr').find('.sid').html();
		var dd = $(this);
		//发送ajax
		$.post('/admin/comment/delete',{id:id},function(data){
			if(data==1){
				dd.parents('tr').remove();
				messages('success','删除成功');
			}else{
				messages('error','删除失败');
			}
		})

		return false;
	})

	//自定义错误函数 
	function messages(er,m)
	{
	   if(er == 'success'){
        $('#messagesuccess').find('span').html(m);
        $('#messagesuccess').show();
        setTimeout("$('#messagesuccess').hide()",5000);
      }else{
        $('#messagedanger').find('span').html(m);
        $('#messagedanger').show();
        setTimeout("$('#messagedanger').hide()",5000);

      }
	}
</script>
@endsection